<template>
  <div v-if="showCard" class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span style="color:red">* </span><span>目的</span>
      </div>
     <!-- <ckeditor :editor-url="editorUrl"   v-model="form.purpose" :config="editorConfig"></ckeditor> -->
     <ckeditor    v-model="form.purpose" :config="editorConfig0"></ckeditor>
    </el-card>
    <el-card class="box-card" style="margin-top: 20px;">
      <div slot="header" class="clearfix">
        <span style="color:red">* </span><span>意义</span>
      </div>
     <!-- <ckeditor :editor-url="editorUrl"   v-model="form.purpose" :config="editorConfig"></ckeditor> -->
     <ckeditor    v-model="form.mean" :config="editorConfig1"></ckeditor>
    </el-card>
    <el-card class="box-card" style="margin-top: 20px;">
      <div slot="header" class="clearfix">
        <span style="color:red">* </span><span>内容安排</span>
      </div>
     <!-- <ckeditor :editor-url="editorUrl"   v-model="form.purpose" :config="editorConfig"></ckeditor> -->
     <ckeditor    v-model="form.content" :config="editorConfig2"></ckeditor>
    </el-card>
    <el-card class="box-card" style="margin-top: 20px;">
      <div slot="header" class="clearfix">
        <span style="color:red">* </span><span>预期成果</span>
      </div>
     <!-- <ckeditor :editor-url="editorUrl"   v-model="form.purpose" :config="editorConfig"></ckeditor> -->
     <ckeditor    v-model="form.expect" :config="editorConfig3"></ckeditor>
    </el-card>
        <el-button style="margin-top: 20px;float: right;"
          type="primary"
          @click="handleAdd"
        >下一步</el-button>
		<el-button   v-hasPermi="['eqxm:team:edit']" style="float: right;margin-right: 10px;margin-top: 20px;" type="primary" @click="back">上一步</el-button>
		

					

  </div>
</template>

<script>
import { listTeamTeacher, getTeamTeacher, delTeamTeacher, addTeamTeacher, updateTeamTeacher, exportTeamTeacher,canChooseList,canChooseStuList } from "@/api/eqxm/teamTeacher";
import CommonUtils from "@/utils/CommonUtils";
import { listTeamStudent, getTeamStudent, delTeamStudent, addTeamStudent, updateTeamStudent, exportTeamStudent } from "@/api/eqxm/teamStudent";
import CKEditor from 'ckeditor4-vue';
import { listTeamResearch, getTeamResearch, delTeamResearch, addTeamResearch, updateTeamResearch, exportTeamResearch } from "@/api/eqxm/teamResearch";
import {getTeam} from '@/api/eqxm/team';
import { mapGetters } from 'vuex';

export default {
  name: "TeamTeacher",
  components: {
      ckeditor: CKEditor.component
  },
  computed: {
    ...mapGetters(['name', 'userName']),
  },
  props:['isAdmin'],
  data() {
    return {
      // 遮罩层
      loading: true,
      stuloading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      stutotal:0,
      // 团队老师表格数据
      teamTeacherList: [],
      teamStudentList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      stuopen:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        teamid: null,
        name: null,
        college: null,
        username: null,
        outlook: null,
        tel: null,
        isheel: null,
      },
      // 表单参数
      form: {},
      stuform: {},
      // 表单校验
      rules: {
      },
      teamId:"",
      teacherOptions:[],
      studentOptions:[],
      stutitle:"",
      searchLoading:false,
      editorData: '',
      editorConfig: {
        readOnly: true,
          // The configuration of the editor.
      },
      editorConfig0: {
        readOnly: true,
          // The configuration of the editor.
      },
      editorConfig1: {
        readOnly: true,
          // The configuration of the editor.
      },
      editorConfig2: {
        readOnly: true,
          // The configuration of the editor.
      },
      editorConfig3: {
        readOnly: true,
          // The configuration of the editor.
      },
      showCard: false,
      //editorUrl: 'https://cdn.ckeditor.com/4.16.0/full/ckeditor.js'
      purpose:'',
      mean:''
    };
  },
  created() {
    this.getList();
    const teamId = CommonUtils.getCurTeamInfo().id;
      // this.teamId=teamId;
      getTeam(this.teamId).then(response => {
          console.log(response.data.createBy == this.name,"3eeee")
          // var status =  response.data.status==0 ||  response.data.status==2 ||  response.data.status==3
          // if(this.isAdmin || response.data.createBy == this.name && status){
          //   this.editorConfig0.readOnly = false;
          //   this.editorConfig1.readOnly = false;
          //   this.editorConfig2.readOnly = false;
          //   this.editorConfig3.readOnly = false;
          // }
          this.showCard = true;
        });
  },
  methods: {
    getList() {
      const teamId = CommonUtils.getCurTeamInfo().id;
      this.teamId=teamId;
      // getTeam(teamId).then(response => {
      //     console.log(response.data.createBy == this.name,"3eeee")
      //     if(response.data.createBy == this.name){
      //       this.editorConfig.readOnly = false;
      //       // this.editorConfig1.readOnly = false;
      //     }
      //   });
      this.queryParams.teamid=teamId;
      listTeamResearch(this.queryParams).then(response => {
        console.log(response)
        if(response.rows.length>0){
          this.form = response.rows[0];
        }

      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        teamid: null,
        purpose: null,
        mean: null,
        content: null,
        expect: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
        this.$parent.jump(4);
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有团队老师数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportTeamTeacher(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    },
    /** 查询学生 */
    remoteMethod(query) {
      if (query !== '') {
        this.searchLoading = true;
        canChooseStuList(query).then(response => {
          console.log(response)
          this.searchLoading = false;
          this.studentOptions = response.rows.filter(item => {
            return item.xm.toLowerCase()
              .indexOf(query.toLowerCase()) > -1;
          });
        });
      } else {
        this.options = [];
      }
    },
    onNamespaceLoaded (CKEDITOR) {
          console.log(666,CKEDITOR)
      },
    onEditorReady (editor) {
        this.ready(editor)
    },
	back(){
		this.$parent.jump(2);
	},
	next(){
		this.$parent.jump(4);
	}
  }
};
</script>
